package com.start.admin.mappers;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.start.admin.entity.StartSysNoticeEntity;
import com.start.admin.vo.StartUserNoticeVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface SysNoticeMapper extends BaseMapper<StartSysNoticeEntity> {
    /**
     * 用户通知
     *
     * @param page
     * @param entity
     * @return
     */
    @Select(" SELECT ssn.*,\n" +
            "               IF(ssnb.id IS NULL, 0, 1) is_read\n" +
            "        FROM start_sys_notice ssn\n" +
            "                 LEFT JOIN start_sys_notice_browse ssnb ON ssn.id = ssnb.notice_id\n" +
            "            AND ssnb.browse_user_id = #{entity.userId}")
    Page<StartSysNoticeEntity> pageUserNotice(@Param("page") Page<StartUserNoticeVo> page, @Param("entity") StartUserNoticeVo entity);
}
